#!/bin/bash

# 脚本会自动识别当前目录下的第一个.jar
# 只需要调整这里
jdkPath=

# abPath=$(cd `dirname $0`;pwd)
abPath=`readlink -f $0`
abPath=${abPath%/*}
cd ${abPath}
jarName=`ls *.jar | head -n 1`
javaPath=${jdkPath}java
jpsPath=${jdkPath}jps
jarId=(`${jpsPath} | grep ${jarName}`)
jarId=${jarId[0]}

# 检查参数个数
if [ $# -eq 0 ]; then
        echo ${abPath} ${jarName}
    echo "Usage: $0 <start/stop/restart>"
    exit 1
fi

start() {

	echo cd ${abPath}
	echo ${javaPath} -jar ./${jarName}

	cd ${abPath}
	mkdir -p logs
	${javaPath} \
	  -Xms256M -Xmx256M \
	  -XX:+HeapDumpOnOutOfMemoryError \
	  -XX:+PrintGCDetails \
	  -jar ./${jarName} \
	  2 >& 1 >> ./logs/console.log &
}

stop() {
	echo kill ${jarId}
	kill ${jarId}
}

restart() {
  stop
  sleep 1
  start
}

${1}